<template>
  <div class="newsinfo-container">
    <!-- 大标题 -->
    <h3 class="title">{{ newsinfo.title }}</h3>
    <!-- 小标题 -->
    <p class="subtitle">
      <span>发表时间：{{ newsinfo.addTime | dataFormat }}</span>
      <span>点击：{{ newsinfo.click }}</span>
    </p>
    <hr>
    <!-- 内容 -->
    <div class="content" v-html="newsinfo.content"></div>
    <!-- 评论子组件 -->
    <commentBox></commentBox>
  </div>
</template>

<script>
import { Toast } from "mint-ui"
//导入评论子组件
import comment from '../subcomponents/comment.vue'

export default {
  data() {
    return {
      id: this.$route.params.id,
      newsinfo: {}
    }
  },
  created() {
    this.getNewsInfo()
  },
  methods: {
    getNewsInfo() {
      this.$http.get('newsinfo/' + this.id).then(result => {
        if (result.body.status === 0) {
          this.newsinfo = result.body.message[0]
        } else {
          Toast('获取新闻失败！')
        }
      })
    }
  },
  components: {
    //注册子组件
    "commentBox": comment
  }
}
</script>

<style>
  .newsinfo-container{
    padding: 5px;
  }
  .newsinfo-container h3{
    font-size: 16px;
  }
  .newsinfo-container .subtitle{
    display: flex;
    justify-content: space-between;
  }
  .newsinfo-container .content img{
    width: 100%;
  }
  .newsinfo-container .content{
    margin-top: 10px;
  }
</style>